﻿<?php

class UserApp extends BaseApp
{
    var $type = 'user';
	
    function index()
    {
			
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);
        $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);		
        $this->display('user/login.view.html');
    }
	
	
    function login()
    {
		
		$username = $_POST['username'];		
		$pwd =  $_POST['pwd'];
		
	    $user = & $GLOBALS['SCup']->_get_user(); 						
	    if($user->login($username,$pwd))
		{
		
	   $notice = &get_message(array('msg'=>'登入成功！','url'=>'?app=default','title'=>'Notice'));
	   $notice ->display();	 
		
		}
		else
		{
	   $notice = &get_message(array('msg'=>'登入失败！','url'=>'?app=user','title'=>'Notice'));
	   $notice ->display();	 
		}
		

    }

    function quit()
    {
		
	   $user = & $GLOBALS['SCup']->_get_user();		
	   if($user->quit())
	   {
	   $notice = &get_message(array('msg'=>'True!','url'=>'?','title'=>'Notice'));
	   $notice ->display();	
	   }
	   else
	   {
	   $notice = &get_message(array('msg'=>'False!','url'=>'?','title'=>'Notice'));
	   $notice ->display();	   
	   
	   }

	   
	   

    }
	

    function editpwd()
    {
		
		$data = $_POST['data'];		
		unset($data['user_id']);				
		$data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
				
		$user = & $GLOBALS['SCup']->_get_user();	
		
	   if($user->pwd($data))
	   {
	   $notice = &get_message(array('msg'=>'Succes!','url'=>'?app=user&act=user','title'=>'Notice'));
	   $notice ->display();		   
	   
	   }
	   else
	   {
	   $notice = &get_message(array('msg'=>'False!','url'=>'?app=user&act=user','title'=>'Notice'));
	   $notice ->display();		   
	   }
	   
    }	

    function edituser()
    {
		$data = $_POST['data'];

        $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
	    $user = & $GLOBALS['SCup']->_get_user();
    
		$user->editmsg($data);
			
        $this->user();
    }
	
    function reg()
    {
		$TB_usertype = &$this->_model('usertype'); 		
		$usertypedata = $TB_usertype->limitshow();
        $this->assign('usertypedata', $usertypedata);
			
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);

        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/register.view.html');

    }

    function doreg()
    {
		
	   $data = $_POST['data'];		
	   $data['user_type'] = intval($data['user_type']);
	   if($data['user_type'])
	   {
		  $TB_usertype = &$this->_model('usertype'); 		
		  $usertypedata = $TB_usertype->oneshow($data['user_type']);
		  if(isset($usertypedata['role_id']))
		  {
		     $roleid = $usertypedata['role_id'];
			/* $data['roleid'] = 'admin:'.$roleid.'|scup:'.$roleid;*/
			 $data['roleid'] = ROLE_P_ID;		  
		  }else
		  {
	         $notice = &get_message(array('msg'=>'不存在此用户类型！','url'=>'?','title'=>'Notice'));
	         $notice ->display();			  
		  }
	   }			
	   $user = & $GLOBALS['SCup']->_get_user();	
		
	   if($user->reg($data))
	   {
	   
	   $notice = &get_message(array('msg'=>'请填写下面内容之后才能登入后台！','url'=>SITE_URL.'/?app=usercon&act=reg2&uid='.$data['username'],'title'=>'提示'));
	   $notice ->display();		   
	   
	   }
	   else
	   {
	   $notice = &get_message(array('msg'=>'注册失败！','url'=>'?','title'=>'提示'));
	   $notice ->display();		   
	   }
	   
    }

    function userpwd()
    {

		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/userpwd.view.html');

    }	

	function userintegral()
    {
        if(!isset($_POST['job'])){
		    $_POST['job'] ='';
		}
		if($_POST['job'] == 'do') {
		    $money = intval($_POST['money']);

            if($money<1 || $money>5000) {
			    $notice = &get_message(array('msg'=>"每次充入的金额范围在1元到5000元之间！",'url'=>'','title'=>'Notice'));
		        $notice ->display();
			}
			
	        $username = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];			
	        $user = & $GLOBALS['SCup']->_get_user();
		    $tempdata = $user->get_info($username);
            if($tempdata['money'] < $money) {
			    $notice = &get_message(array('msg'=>"您的账上余额为:".$tempdata['money']."元，余额不足！",'url'=>'','title'=>'Notice'));
		        $notice ->display();
            }		
			$jifeng1 = $money * QIAN_JIFENGSHU ;
			$TB_user = &$this->_model('user');
	        $pay = $TB_user->moneypay($money,$GLOBALS['SCup']->SCup_user_msg['user_id'],0);			    				
            $ary=array(
				   'userid' => $GLOBALS['SCup']->SCup_user_msg['user_id'],
				   'type' => '0',
				   'name' => '使用人民币购买积分',
				   'intro' => '支付总金额'.$money.'元（购买积分数为：'.$jifeng1.'）',
				   'money' => $money,
				   'time' => time(),
		    );
		    $TB_user->moneylog($ary);
			

	        $TB_integral = &$this->_model('integral');	

			$totaljifeng =$tempdata['integral'];
              $jifeng = $jifeng1 ;
		      $data=array(
		        'userid' => $tempdata['user_id'],
				'user_name' => $username,
				'role_id' => $tempdata['role_id'],
				'type' => 1,
				'name' => '自己人民币兑换积分，'.$GLOBALS['SCup']->SCup_user_msg['data']['user_name'].'操作',
				'intro' => '自己人民币兑换积分，'.$GLOBALS['SCup']->SCup_user_msg['data']['user_name'].'操作',
				'integral' => $jifeng,
				'time' => time(),
				'cao_username' => $GLOBALS['SCup']->SCup_user_msg['data']['user_name'],
		      );	
			  $data['totalintegral'] = $totaljifeng+$jifeng;
		      $TB_integral->integraladd($jifeng,$tempdata['user_id']);
				 $TB_integral->post($data);  
		    $notice = &get_message(array('msg'=>'兑换成功！','url'=>'?app=user&act=userintegral','title'=>'Notice'));
		    $notice ->display();
		 
			
		}
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 

	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$data = $user->get_info($GLOBALS['SCup']->SCup_user_msg['user_id'] , 'user_id');
        $this->assign('data', $data);		
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');		
        $this->display('user/userintegral.view.html');
    }	
	
    function user()
    {
	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$data = $user->get_info($GLOBALS['SCup']->SCup_user_msg['user_id'] , 'user_id');
        $this->assign('data', $data);
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user.view.html');

    }	
	
//团购卷下载到手机
    function mobphone()
    {

       if(!isset($_POST['step']))
	   {
	   $_POST['step'] = '';
	   }
       if(!isset($_POST['mobphone']))
	   {
	       $_POST['mobphone'] = '';
	   }
	   if(!isset($_GET['id']))
	   {
	     $_GET['id'] = '';
	   }	  
       $id = intval($_GET['id']);	   
	   	       
	    $mobphone = $_POST['mobphone'];
	    $step = $_POST['step'];
        
       if($step == 'domobphone')
	   {
 
	      if( !preg_match("/^1(3|5|8)([0-9]{9})$/i",$mobphone) )
	      {
		     $notice = &get_message(array('msg'=>"手机号码有误!",'url'=>'','title'=>'Notice'));
		     $notice ->display();		   
		   
	      }
	       if(!isset($_POST['id']))
	       {
	       $_POST['id'] = '';
	       }	  
          $id = intval($_POST['id']);

	      $TB_user = &$this->_model('user');
		  $order = $TB_user->getticket($id);


	      if($order['password']=='')
	      {
		   $notice = &get_message(array('msg'=>'读取优惠券出现错误！','url'=>'','title'=>'Notice'));
		   $notice ->display();
	      }

           if(isset($order['bookprice'])&&$order['bookprice']!=0)
	       {
	       $order['nowprice'] = $order['bookprice'];
	       }
	       $msg=sms_send($mobphone,"欢迎使用牡丹商城peogoo优惠卷，编号：".$order['number'].",密码：".$order['password'].",有效期：".date("Y-m-d G:i:s", $order['perioddate']).",产品名：".$order['name']."，团购名：".$order['groupname']."，商家名：".$order['sellername'].",商家地址：".$order['selleraddress']."！");

	      if($msg!==1)
		  {
		     $notice = &get_message(array('msg'=>"系统发送短信失败,有可能是你的手机号码有误,也有可能是系统的短信接口平台出现故障,请联系管理员在后台检查短信平台接口!",'url'=>'','title'=>'Notice'));
		     $notice ->display();			 
	      }
		   $notice = &get_message(array('msg'=>'优惠卷成功下载到手机号为：'.$mobphone.'上了！','url'=>'','title'=>'Notice'));
		   $notice ->display();		 
		 		    
	   }
	
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
		
        $this->assign('step', $step);
        $this->assign('mobphone', $mobphone);
        $this->assign('id', $id);
								
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	

		
        $this->display('user/user_mobphone.view.html');

    }	

//手机验证
    function checkmobphone()
    {
       if(!isset($_POST['step']))
	   {
	   $_POST['step'] = '';
	   }
          if(!isset($_POST['mobphone']))
	      {
	       $_POST['mobphone'] = '';
	      }	       
	    $mobphone = $_POST['mobphone'];
	    $step = $_POST['step'];
        
       if($step == 'domobphone')
	   {

		   $mobphone = $_POST['mobphone'];  
	      $code=rand(1000,9999);
	      if( !preg_match("/^1(3|5|8)([0-9]{9})$/i",$mobphone) )
	      {
		     $notice = &get_message(array('msg'=>"手机号码有误!",'url'=>'','title'=>'Notice'));
		     $notice ->display();		   
		   
	      }
	      $msg=sms_send($mobphone,"你的验证码是:$code");

	      if($msg!==1)
		 {
		     $notice = &get_message(array('msg'=>"系统发送短信失败,有可能是你的手机号码有误,也有可能是系统的短信接口平台出现故障,请联系管理员在后台检查短信平台接口!",'url'=>'','title'=>'Notice'));
		     $notice ->display();			 
	     }
         $GLOBALS['SCup']->SCup_user_msg['data']['mobphone_yz_code_temp'] = $code.'_'.$mobphone;
		 
		 		    
	   }
	   else if ($step == 'overmobphone')
	   {

          if(!isset($_POST['yznum']))
	      {
	       $_POST['yznum'] = '';
	      }	

		   $yznum = $_POST['yznum']; 		   		  		  
    	  if(!$yznum)
		  {
		     $notice = &get_message(array('msg'=>"请输入验证码",'url'=>'','title'=>'Notice'));
		     $notice ->display();			  
	      }elseif(!isset($GLOBALS['SCup']->SCup_user_msg['data']['mobphone_yz_code_temp'])||empty($GLOBALS['SCup']->SCup_user_msg['data']['mobphone_yz_code_temp']))
		  {
		     $notice = &get_message(array('msg'=>"资料有误",'url'=>'','title'=>'Notice'));
		     $notice ->display();		  
	      }else
		  {
		    $code=$mobphone1=0;
		    list($code,$mobphone1)=explode("_",$GLOBALS['SCup']->SCup_user_msg['data']['mobphone_yz_code_temp'] );
		    if($code!=$yznum||$mobphone!=$mobphone1)
			{
		     $notice = &get_message(array('msg'=>"验证码不对",'url'=>'','title'=>'Notice'));
		     $notice ->display();				
		    }
	      }
		     $notice = &get_message(array('msg'=>"恭喜你,你的手机号码成功通过审核!",'url'=>'','title'=>'Notice'));
		     $notice ->display();	
   
	   }
		
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
		
        $this->assign('step', $step);
        $this->assign('mobphone', $mobphone);
						
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_checkmobphone.view.html');

    }	


//邮箱验证
    function checkemail()
    {
	     $step = '';
        if(isset($_POST['step']))
	    {
	       $step = $_POST['step'];
	    }
        if(isset($_GET['step']))
	    {
           $step = $_GET['step'];
	    }		
	    
        if($step =='do') {
			if($_POST['email']) {
			    $email = $_POST['email'];
			}else {
                $email = $GLOBALS['SCup']->SCup_user_msg['data']['user_email'];
            }			
	        if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email)) {
			    $notice = &get_message(array('msg'=>"邮箱不符合规则",'url'=>'','title'=>'Notice'));
		        $notice ->display();				
	        }
            $succeed=0;	          
			
            $username = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'] ;
			$uid = $GLOBALS['SCup']->SCup_user_msg['user_id'];
	        $Title="来自".SITE_TITLE."的邮箱验证信息!";
	        $pid= md5($username.'_'.$email);
	        $Content="请点击以下网址,以完成邮箱的验证:<br><a href='".SITE_URL."/?app=user&act=checkemail&step=yz&uid=$uid&pid=$pid'>".SITE_URL."/?app=user&act=checkemail&step=yz&uid=$uid&pid=$pid</a>";		

		    if(!MAIL_SERVER ||! MAIL_PORT ||!MAIL_ID || !MAIL_PW )
		    {
			    $notice = &get_message(array('msg'=>"请管理员设置邮件服务器",'url'=>'','title'=>'Notice'));
		        $notice ->display();					
		    }
		    require_once(ROOT_PATH."/lib/mail.lib.php");
		    $smtp = new smtp(MAIL_SERVER,MAIL_PORT,true,MAIL_ID,MAIL_PW);
		    $smtp->debug = false;
		    if($smtp->sendmail($email,MAIL_ID, $Title, $Content, "HTML")){
			    $succeed=1;
		    }

	        if($succeed){
			    $notice = &get_message(array('msg'=>"系统刚刚发了一封验证信息到你邮箱,请尽快查收,以完成邮件验证",'url'=>'','title'=>'Notice'));
		        $notice ->display();				
	        }else{
			    $notice = &get_message(array('msg'=>"邮件发送失败.请管理员检查邮箱服务器设置",'url'=>'','title'=>'Notice'));
		        $notice ->display();	
	        }			
		
		}
		if($step =='yz') {
		    		 
		}
	
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 

        $this->assign('email', $GLOBALS['SCup']->SCup_user_msg['data']['user_email']);
						
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);				
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_checkemail.view.html');

    }	
	
	
	
	
	
    function userindex()
    {

	    $TB_user = &$this->_model('user');
		$money = $TB_user->moneyuser();
		
        $this->assign('money', $money);
        $this->assign('userdata',$GLOBALS['SCup']->_get_user()->get_info($GLOBALS['SCup']->SCup_user_msg['data']['user_name']));	
        $this->assign('userrole',$GLOBALS['SCup']->SCup_user_msg['role_name']);			
		
		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		
        $this->assign('navigation', $nav->_get_nav());	
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/userindex.view.html');

    }






	

    function ticket()
    {
		if(!isset($_GET['type']))
		{
		$_GET['type'] ='';
		}    

	$t1=$t2=$t3=$t4=3;
    $type = intval($_GET['type']);
	
	if($type=='')$t1=2;
	if($type=='1')$t2=2;
	if($type=='3')$t3=2;
	if($type=='2')$t4=2;

	    $TB_user = &$this->_model('user');
		$data = $TB_user->ticketmy($type);
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	

		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_ticket.view.html');

    }	


    function printticket()
    {
       $id = intval($_GET['id']);

	    $TB_user = &$this->_model('user');
		$order = $TB_user->getticket($id);


	   if($order['password']=='')
	   {
		 $notice = &get_message(array('msg'=>'读取优惠券出现错误！','url'=>'','title'=>'Notice'));
		 $notice ->display();
	   }

       if(isset($order['bookprice'])&&$order['bookprice']!=0)
	   {
	   $order['nowprice'] = $order['bookprice'];
	   }

        $this->assign('order', $order);


		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_printticket.view.html');

    }	





    function order()
    {
		if(!isset($_GET['type']))
		{
		$_GET['type'] ='';
		} 
	    $TB_buy = &$this->_model('buy');
	    $TB_buy->uporder($GLOBALS['SCup']->SCup_user_msg['user_id']);
	    $t1=$t2=$t3=3;

	$type = $_GET['type'];
    $pay='';
	if($type!='')
	{
		if($type=='payed')
		{
			$pay=1;
			 $t2=2;
		}else
		{
			$pay=0;
			 $t3=2;
		}
	}else
	{
		$pay='no';	
		$t1=2;
	}

	$data=$TB_buy->getorderlist($GLOBALS['SCup']->SCup_user_msg['user_id'],$pay);



		$this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);





		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_order.view.html');

    }	


    function productorder()
    {
			if(!isset($_GET['type']))
		{
		$_GET['type'] ='';
		} 

	$t1=$t2=$t3=3;

	$type = $_GET['type'];
    $pay='';
	if($type!='')
	{
		if($type=='payed')
		{
			$pay=1;
			 $t2=2;
		}else
		{
			$pay=0;
			 $t3=2;
		}
	}else
	{
		$pay='no';		
		$t1=2;
	}

	    $TB_buy = &$this->_model('buy');
	$data=$TB_buy->getproductorderlist($GLOBALS['SCup']->SCup_user_msg['user_id'],$pay);

		$this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);

		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_productorder.view.html');

    }

	function pordercontent()
	{
		$id=$_GET['id'];		 	
		$TB_order = &$this->_model('do');  				
		$order = $TB_order->ordercontent($id);
	    $TB_payment = &$this->_model('payment');
	    $pay = $TB_payment->paychoose(intval($order['paytype']));
		$order['paytypename'] = $pay['pay_name'];
        $product = $this->buyidstr_to_product_msg($order['productmsg']);
		$moduledata	= array();	
	    $tempmoduledata =  & $GLOBALS['SCup']->_get_module_list_data();
		foreach($tempmoduledata as $key => $value)
		{
            $moduledata[$value['id']] = $key;
		}
        unset($tempmoduledata);			
        $this->assign('moduledata',  $moduledata);		
        $this->assign('product', $product);
        $this->assign('order', $order);
 		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		} 
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	    $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');			
        $this->display('user/do_order_content.view.html');
	}

    function buyidstr_to_product_msg($buyidstr,$ischeck=0)
	{
		$return_data = array();
		$productdata = array();
		$productcheck = array();
		$shopmoney = 0 ;
		$totalmoney = 0 ;		
		$numcheck = true;		
		$check = true ;		
		$buyarray = $this->buyidstr_to_array($buyidstr);				
        if(!empty($buyarray))
		{
		   $sql_in_str = array();
		   foreach($buyarray as $key=>$value)
		   {
		       if(!isset($sql_in_str[$value['0']]))$sql_in_str[$value['0']]='';
		       $sql_in_str[$value['0']].=$value['2'].',';
		   }
	       $db = & get_db();		   
		   foreach($sql_in_str as $key =>$value)
		   {
		      $fids= substr($value,0,-1);
			  $productdata[$key] = $db->get_all("SELECT * FROM ".DB_PREFIX."content_".$key." WHERE id IN ($fids)");			  
		   }   		   		  
		}
		if($ischeck&&!empty($buyarray)&&!empty($productdata))
		{
		    foreach($productdata as $key => $value)
			{
			    foreach($value as $key1 => $value1)
				{
				   $keystr = $key .'_'. $value1['cat_id'] .'_'. $value1['id'];
				   $productcheck[$keystr]['check']=1;
				   $productcheck[$keystr]['shoptype']=$value1['shoptype'];
				   $productcheck[$keystr]['numcheck']=$value1['shopnum'];
				   $shopmoney+=$value1['shopmoney'];
		           $totalmoney+=$value1['nowprice']*$buyarray[$keystr]['3'];
				}				
			}					
		    foreach($buyarray as $key => $value)
			{
				if(!isset($productcheck[$key]))
				{
				$productcheck[$key]['check']=0;
				$productcheck[$key]['name']='';
				$productcheck[$key]['numcheck']=0;					
				$check = false;					
				}else
				{
				   if($productcheck[$key]['numcheck']>=$value['3'])
				   {
				     $productcheck[$key]['numcheck']=$value['3'];				   
				   }else
				   {
				     $productcheck[$key]['numcheck']=0;	
					 $numcheck = false;				   
				   }			
				}				
			}
		}
		$return_data['buy'] = $buyarray;
		$return_data['product'] = $productdata;
		$return_data['productcheck'] = $productcheck;		
		$return_data['check'] = $check;	
		$return_data['numcheck'] = $numcheck;
		$return_data['shopmoney'] = $shopmoney;	
		$return_data['totalmoney'] = $totalmoney;							
		return $return_data;		
	}

    function buyidstr_to_array($buyidstr)
	{
        $detail=del_empty_var(explode(",",$buyidstr));
		$buyarray = array();
        foreach( $detail AS $key=>$value)
		{
		   $temp_data = explode('_', $value);
		   if(!isset($temp_data['0']))$temp_data['0']=0;
		   if(!isset($temp_data['1']))$temp_data['1']=0;
		   if(!isset($temp_data['2']))$temp_data['2']=0;
		   if(!isset($temp_data['3']))$temp_data['3']=1;		   						   
	       if(intval($temp_data['2'])>0||intval($temp_data['0'])>0)
		   {
		      $key_str = $temp_data['0'].'_'.$temp_data['1'].'_'.$temp_data['2'];
              $buyarray[$key_str]['0']=$temp_data[0];
              $buyarray[$key_str]['1']=$temp_data[1];			  
              $buyarray[$key_str]['2']=$temp_data[2];
              $buyarray[$key_str]['3']=$temp_data[3];			  			  
	       }
        }
		return $buyarray;		
	}


    function money()
    {

	    $TB_user = &$this->_model('user');
		$money = $TB_user->moneyuser();


	   $data=$TB_user->showmoneylog($GLOBALS['SCup']->SCup_user_msg['user_id']);


        $this->assign('money', $money);
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);

		require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_money.view.html');

    }	

    function addmoney()
    {

	    $TB_user = &$this->_model('user');
		$money = $TB_user->moneyuser();

	    $TB_payment = &$this->_model('payment');
	    $pay = $TB_payment->paytype();
        $this->assign('pay', $pay);
        $this->assign('money', $money);
     	require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_addmoney.view.html');

    }	

function topay($app,$returnurl,$pay)
{
	$payment=unserialize($pay['pay_config']);
	$returnurl.='&pay='.$app;
	include_once(ROOT_PATH . '/lib/pay/'.$app.'.pay.php');
    $app_pay_class_name = ucfirst($app);
    $app_pay     = new $app_pay_class_name();
	$bottom=$app_pay->payTo($payment,$returnurl,$pay);
	return $bottom;
	exit;
}

    function doaddmoney()
    {
    if(!isset($_POST['money'])){ $_POST['money']='';}
    if(!isset($_POST['paytype'])){ $_POST['paytype']='';}	
	
    $money = ceil($_POST['money']);
    $paytype = intval($_POST['paytype']);


	if($paytype=='')
	{
		 $notice = &get_message(array('msg'=>'您没有选择支付方式或者没有适合的支付接口！','url'=>'','title'=>'Notice'));
		 $notice ->display();	
	}

	if(!is_numeric($money) || $money<=0)
	{
			 $notice = &get_message(array('msg'=>'充值金额必须大于等于0！','url'=>'','title'=>'Notice'));
		 $notice ->display();	
	}

	    $TB_payment = &$this->_model('payment');
	    $pay = $TB_payment->paychoose($paytype);

	$pay['orderid']=time().rand(10000,99999);
	$pay['price']=$money;
	$pay['name']='账户充值';

	$returnurl = SITE_URL.'/?app=user&act=readdmoney';
	$bottom=$this -> topay($pay['pay_code'],$returnurl,$pay);

		
        $this->assign('bottom', $bottom);
        $this->assign('pay', $pay);
        $this->assign('money',  $money);
        $this->assign('paytype', $paytype);

     	require(ROOT_PATH . '/lib/nav.lib.php');
		
		$nav = new Nav($GLOBALS['SCup']->SCup_nav_file);
		if(isset($GLOBALS['SCup']->SCup_user_msg['data']['user_name']))
		{
        $this->assign('username',$GLOBALS['SCup']->SCup_user_msg['data']['user_name']);			
		}
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	        
		$this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('user/user_doaddmoney.view.html');

    }


function readdmoney(){
	$pay_code = !empty($_REQUEST['pay']) ? trim($_REQUEST['pay']) : '';

    if($pay_code=='')
	{
			 $notice = &get_message(array('msg'=>'错误！','url'=>'?','title'=>'Notice'));
		 $notice ->display();
	}


	include_once(ROOT_PATH . '/lib/pay/'.$pay_code.'.pay.php');
    $app_pay_class_name = ucfirst($pay_code);
    $app_pay     = new $app_pay_class_name();
	$msg=$app_pay->addmymoney();

	if(is_array($msg)){
		$this -> dopay($msg['price'],$msg['orderid']);
	}else{

		 $notice = &get_message(array('msg'=>'$msg','url'=>'?','title'=>'Notice'));
		 $notice ->display();	
	}
	exit;
}


function dopay($price,$orderid)
{
 	if($price=='' || $orderid=='')
	{
		 $notice = &get_message(array('msg'=>'支付失败!','url'=>'?','title'=>'Notice'));
		 $notice ->display();	

	}
	if($price>0)
	{
       	    $TB_user = &$this->_model('user');

		$pay=$TB_user->moneyadd(intval($price),$GLOBALS['SCup']->SCup_user_msg['user_id']);
		$ary=array(
				'userid' => $GLOBALS['SCup']->SCup_user_msg['user_id'],
				'type' => 1,
				'name' => '充值账户',
				'intro' => '您为账户充值'.$price.'元',
				'money' => $price,
				'time' => time(),
		);
		$TB_user->moneylog($ary);
	}
		$ary=array(
		'id' 	=> $orderid,
		'money' => $price,
		'userid'=> $GLOBALS['SCup']->SCup_user_msg['user_id'],
		'user_name'=> $GLOBALS['SCup']->SCup_user_msg['data']['user_name'],		
		'paytime'=> time(),
	     );
       $TB_user->addmoney($ary);

		 $notice = &get_message(array('msg'=>'充值成功！','url'=>'?app=user&act=money','title'=>'Notice'));
		 $notice ->display();

}


    function cancel()
    {


      $orderid = $_GET['oid'];
	    $TB_buy = &$this->_model('buy');

	    $TB_buy->ordertype($orderid,'0');

		 $notice = &get_message(array('msg'=>'您已经成功取消该订单！','url'=>'?app=user&act=order','title'=>'Notice'));
		 $notice ->display();

    }	

    function kindeditor()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile($this->type.'/'.$w);	
    }
	
	
    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }	
	 if(!isset($_GET['jsfun']))
	 {
	 $_GET['jsfun']='';
	 }		 
	 if(!isset($_GET['putid']))
	 {
	 $_GET['putid']='';
	 }		 
	 if(!isset($_GET['uppic']))
	 {
	 $_GET['uppic']='';
	 }	
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	 	 	
		$action = $_POST["action"];		
		$id = intval($_GET['id']);		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['putid'];
		if(!empty($_GET['uppic']))
		{
		$uppic = $_GET['uppic'];		
		}	
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];

        $this->assign('jsfun', $jsfun);		


        $this->assign('uppic', $uppic);		
	
				

        $this->assign('edit', $edit);		


        $this->assign('picurl', $picurl);

        $this->assign('tf', $tf);
						
		if($action == 'post')
		{
			 if(!isset($_POST['jsfun']))
	 {
	 $_POST['jsfun']='';
	 }	
	 if(!isset($_POST['uppic']))
	 {
	 $_POST['uppic']='';
	 }		 
	 if(!isset($_POST["edit"]))
	 {
	 $_POST["edit"]='';
	 }		 
	 if(!isset($_POST["picurl"]))
	 {
	 $_POST["picurl"]='';
	 }	
	 if(!isset($_POST['id']))
	 {
	 $_POST['id']='';
	 }		 
		       $jsfun = $_POST['jsfun'];
		       $uppic = $_POST['uppic'];		
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		
		       $filedname = trim(str_replace(array("UP_"),array(""),$uppic)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			   if($edit=='editp' && $picurl)
			   {

			          $TB_new = &$this->_model('content');			    		 		 		
		              $TB_new->editpicurl($id,array("$filedname"=>$newfile),$this->table_id);
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }					   
			   }

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }				 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

              if($tf=='pic')
			  {
	           echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改图片</A>";			  
			  }else
			  {
	           echo "<A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改文件</A>";			  
			  }

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);		    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);		
        $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));

        $this->assign('login_icon', $GLOBALS[SCup]->SCup_user_checking);				
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS[SCup]->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
	    $this->assign('site_url',SITE_URL);		
		
        $this->display('upfile.view.php');
    }




    function pupfile()
    {	
	 if(!isset($_GET["action"]))
	 {
	 $_GET["action"]='';
	 }
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	        if(!isset($_POST['id']))
	        {
	          $_POST['id']='';
	        }  	
		$action = $_GET["action"];			
		$action || $action = $_POST["action"];
		
		$id = intval($_GET['id']);
		$cid =$id;
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	
						
		if($action == 'post')
		{
		
		 	   $id || $id = intval($_POST['id']);		
               $cid = $id;
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
			   
               unset($data);
		       $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];		       
               $data['con_id'] = $id;
               $data['appname'] = $this->type;			   
			   $data['file_url'] = $updata[1]['path'];
			   $data['size'] = $updata[1]['size'];
			   $data['type'] = $updata[1]['type'];
			   			   
			   $TB_new = &$this->_model('upfile');			    		 		 		
		       $TB_new->post($data);
					   	   
	    }
		else if($action == 'del')
		{
			   $id || $id = intval($_POST['id']);   
			   $TB_new = &$this->_model('upfile');
			   
			    $picdata = $TB_new->oneshow($id);
				$picurl = $picdata['file_url'];
                $cid = $picdata['con_id'];
			   			    		 		 		
		       $TB_new->del($id);
					  
		       $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }			
		
		}			

	    $TB_new = &$this->_model('upfile');

        $this->assign('picdata', $TB_new ->selct($cid,$this->type));		
        $this->assign('tf', $tf);	
        $this->assign('id', $cid);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);		
        $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));

        $this->assign('login_icon', $GLOBALS[SCup]->SCup_user_checking);				
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS[SCup]->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
	    $this->assign('site_url',SITE_URL);	
		
        $this->display('pupfile.view.php');
    }

	

}






?>